package operativa.action.utils;

import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import operativa.bean.entity.Location;

public class CSVGenerator {

	public static void generateCsvFile(String sFileName,List<SimulationRow> simulationResult,List<Location> fishShopsList)
	   {
		try
		{
		    FileWriter writer = new FileWriter(sFileName);
		    //header
			writer.append("Mes");
			writer.append(',');
			for (Location location : fishShopsList) {
				writer.append(location.getName());
				writer.append(',');
			}
			writer.append("Costo Total");
		    writer.append('\n');
		    
		    //content	 
		    for (SimulationRow row : simulationResult) {
				writer.append(new Integer(row.getMonth()).toString());
				writer.append(',');
				for (Integer demand : row.getDemands()) {
					writer.append(demand.toString());
					writer.append(',');
				}
				writer.append(new Float(row.getTotalCost()).toString());
				writer.append('\n');
			}
		   
		    writer.flush();
		    writer.close();
		}
		catch(IOException e)
		{
		     e.printStackTrace();
		} 
	    }
}